package com.wm.controller;

import com.wm.entity.RbacPerm;
import com.wm.entity.ResponseResult;
import com.wm.service.PermService;
import com.wm.util.Audience;
import com.wm.util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/perm")
public class PermController {
    @Autowired
    private PermService permService;
    @Autowired
    private Audience audience;

    @GetMapping("/getUser")
    public ResponseResult<List<RbacPerm>> getPermsById(@RequestHeader("token") String jwt) {
        int userId = JwtUtil.parseJwtForId(jwt, audience);
        return new ResponseResult<>(permService.getPermsByUserId(userId));
    }

}
